package org.zuel.boot.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.zuel.boot.demo.model.DemoPerm;
import org.zuel.boot.demo.service.IPermService;

import java.util.List;

/**
 * @Description:
 * @Author: Athrun
 * @Date: 2020/11/27
 * @Version 1.0
 */
@RestController
@RequestMapping(value = "/perm")
public class PermController {

    private final IPermService permService;

    @Autowired
    public PermController(IPermService permService) {
        this.permService = permService;
    }

    @GetMapping(value = "/list")
    public Object list(@RequestParam(name = "spell_code", required = false) String spellCode,
                       @RequestParam(name = "name", required = false) String name,
                       @RequestParam(name = "con", required = false) String con,
                       @RequestParam(name = "page", defaultValue = "1") Integer page,
                       @RequestParam(name = "limit", defaultValue = "10") Integer limit,
                       @RequestParam(name = "sort", defaultValue = "module_id, menu_id, order_num") String sort,
                       @RequestParam(name = "order", defaultValue = "asc") String order) {
        return permService.list(spellCode, name, con, page, limit, sort, order);
    }

    @GetMapping(value = "/read/{id}")
    public Object read(@PathVariable("id") Integer id) {
        return permService.read(id);
    }

    @PostMapping(value = "/add")
    public Object add(@RequestBody DemoPerm model) {
        return permService.add(model);
    }

    @PostMapping(value = "/edit")
    public Object edit(@RequestBody DemoPerm model) {
        return permService.edit(model);
    }

    @GetMapping(value = "/del")
    public Object del(@RequestParam(name = "ids") List<Integer> ids) {
        return permService.del(ids);
    }
}
